-- CALC_ALADDIN_LAMP_PROPS

-- 计算阿拉丁神灯（宝物）属性加成
-- @param classId    阿拉丁神灯id
return function(classId)
    -- 需要同步修改服务器的公式

    -- 需要按照下面的顺序拼接属性
    -- 每进入下一层，恢复魔法值+6
    -- 降低灯油消耗+1
    -- 降低魔法消耗+1
    -- 攻击+x
    -- 魔力+x
    -- 生命值+x
    -- 魔法值+x
    -- 降低反射效果+x%
    -- 降低摄魔效果+x%
    -- 降低僵化效果+x%
    -- 黄金灯油掉落概率+x%
    local order = {
        "cost_oil", "cost_mp", "attack",
        "magic", "hp", "mp", "reflex",
        "absorb_mp", "rigid", "gold_oil",
    };

    local lampProp = ME.user.dbase:query("lamp_prop", {});
    local ret = {};

    for index, key in pairs(order) do
        repeat
            local level = lampProp[key];
            if type(level) ~= "number" or level <= 0 then
                break;
            end

            if key == "cost_oil" then
                -- 灯油消耗减少
                table.insert(ret, { PropM.getPropId("reduce_cost"), "lamp_oil", 1, -1, });
            elseif key == "cost_mp" then
                -- 减少魔法值消耗
                table.insert(ret, { PropM.getPropId("reduce_cost"), "mp", 1, -1, });
            elseif key == "attack" then
                -- 攻击
                table.insert(ret, { PropM.getPropId("attrib2"), "attack", level, -1, });
            elseif key == "magic" then
                -- 魔力值
                table.insert(ret, { PropM.getPropId("attrib2"), "magic", level, -1, });
            elseif key == "hp" then
                -- 最大生命
                table.insert(ret, { PropM.getPropId("attrib2"), "max_hp", 10 * level, -1, });
            elseif key == "mp" then
                -- 最大魔法值
                table.insert(ret, { PropM.getPropId("attrib2"), "max_mp", 10 * level, -1, });
            elseif key == "reflex" then
                -- 降低反射效果
                table.insert(ret, { PropM.getPropId("reflex_resist"), 1, math.min(70 * level, 1000), -1, });
            elseif key == "absorb_mp" then
                -- 降低摄魔效果
                table.insert(ret, { PropM.getPropId("reduce_negative"), "absorb_mp", math.min(70 * level, 1000), -1, });
            elseif key == "rigid" then
                -- 降低僵化效果
                table.insert(ret, { PropM.getPropId("reduce_negative"), PropM.getPropId("rigid"), math.min(70 * level, 1000), -1, });
            elseif key == "gold_oil" then
                -- 黄金灯油转化率
                table.insert(ret, { PropM.getPropId("drop_rate"), 7169, math.min(70 * level, 1000), -1, });
            end
        until true;
    end

    return ret;
end
